<template>
  <div id="dataaudit">
    <el-card class="box-card" style="margin:15px">
      <div style="margin-bottom:10px">
        <el-button size="small" type="primary" icon="el-icon-printe" @click="clickBuban()">布板</el-button>
        <el-button size="small" type="primary" icon="el-icon-printe" @click="clickPrint">打印</el-button>
        <!-- <el-button size="small" type="primary" icon="el-icon-printe" @click="clickPrint">下载</el-button> -->
        <!-- <el-button size="small" type="primary" icon="el-icon-printe" @click="clickPrint">上传</el-button> -->
        <el-button size="small" type="primary" icon="el-icon-folder-checked" @click="clickAudit">审核</el-button>
        <el-button size="small" @click="clickDelete">删除</el-button>
        <el-button size="small" @click="getList(basicData)">刷新</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%;padding:5px;"
        :header-cell-style="{
          background: '#333333',
          color: '#ffffff',
          textAlign: 'center'
        }"
        @selection-change="selectChanage"
      >
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" prop="batchNumber" label="实验批号" width="150" />
        <el-table-column align="center" prop="experimentCode.data" label="实验项目" />
        <el-table-column align="center" prop="qualityControl.data" label="质控批号" />
        <el-table-column align="center" prop="reagent1.data" label="试剂1" />
        <el-table-column align="center" prop="reagent2.data" label="试剂2" />
        <el-table-column align="center" prop="swatchTime" label="布板日期" width="100">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.swatchTime ? scope.row.swatchTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="sampleCount" label="样本数量" />
        <el-table-column align="center" prop="swatchMan" label="实验人员" />
        <el-table-column align="center" prop="flowStatus.data" label="审核状态" />
      </el-table>
      <el-pagination
        :current-page="basicData.current"
        :page-size="basicData.size"
        :total="total"
        layout="slot, total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <span
          v-if="tableData.length > 0"
          style="font-weight: 400;color:#606266"
        >已选中{{ tableData.length }}条，</span>
      </el-pagination>
    </el-card>

    <!-- 审核 -->
    <el-dialog
      width="85%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="审核"
      :visible.sync="auditShow"
      append-to-body
    >
      <el-form ref="projectManageForm" :model="auditFormData" label-width="120px" size="small">
        <el-row style="margin-bottom:10px !important">
          <el-col :span="6">
            <el-form-item label="实验编号:">
              <el-input size="mini" v-model="queryData.expNum" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="母亲姓名:">
              <el-input size="mini" v-model="queryData.momName" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="实验结果:">
              <el-select v-model="queryData.experimentValueResult.key">
                <el-option
                  :label="item"
                  :value="key"
                  v-for="(item, key, index) in dicts.EXPERIMENT_RESULT"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-button
              size="mini"
              type="primary"
              @click="clickResult"
              style="margin-left:15px  !important;"
            >重置</el-button>
          </el-col>
        </el-row>
        <el-row :span="24" style="margin-bottom:1vw !important;display:flex">
          <div v-for="(item,index) in hintList" :key="index" style="margin-left:1vw;">
            <span style="font-size: 0.8vw;font-weight: bold;">{{item.indicatorCodeName}}：</span>
            <span style="font-size:0.7vw">{{item.hintCount}}</span>
          </div>
        </el-row>
        <el-row>
          <el-table
            ref="dormitoryTable"
            row-key="sampleId"
            :data="tables"
            stripe
            style="width: 100%;"
            :header-cell-style="{
              background: '#333333',
              color: '#ffffff',
              textAlign: 'center'
            }"
            class="import-table"
            :cell-style="tableRowStyle"
          >
            <el-table-column align="center" type="index" width="65" />
            <el-table-column align="center" label="实验编号" width="150" prop="expNum" />
            <el-table-column align="center" label="alpha" width="80" prop="alpha-THA" />
            <el-table-column align="center" label="beta" width="80" prop="beta-THA" />
            <el-table-column align="center" label="M-Hb" width="80" prop="M-Hb" />
            <el-table-column align="center" label="条形码号" width="150" prop="barCode" />
            <el-table-column align="center" label="采血日期" width="100" prop="bloodTime">
              <template slot-scope="scope">
                <span>
                  {{
                  scope.row.bloodTime ? scope.row.bloodTime.substr(0, 10) : ""
                  }}
                </span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="母亲姓名" prop="momName" width="100" />
            <el-table-column align="center" label="性别" prop="babySex.data" width="50" />
            <el-table-column align="center" label="出生日期" width="100" prop="birthTime">
              <template slot-scope="scope">
                <span>
                  {{
                  scope.row.birthTime ? scope.row.birthTime.substr(0, 10) : ""
                  }}
                </span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="所属医院"
              prop="hospitalId.data.label"
              show-overflow-tooltip
            />
            <el-table-column align="center" label="实验项目" width="80" prop="experimentCode.data" />
            <el-table-column align="center" label="实验日期" width="100" prop="experimentDate">
              <template slot-scope="scope">
                <span>
                  {{
                  scope.row.experimentDate
                  ? scope.row.experimentDate.substr(0, 10)
                  : ""
                  }}
                </span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="实验结果"
              width="100"
              prop="experimentValueResult.data"
            />
            <el-table-column align="center" label="实验数据" prop="experimentValue" width="80">
              <template slot-scope="scope">
                <span
                  style="color: #1890ff;cursor: pointer;"
                  @click="clickSeeExpValue(scope.row.experimentValue)"
                >点击查看</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="实验结论" prop="experimentResult.key">
              <template slot-scope="scope">
                <el-select
                  size="mini"
                  v-model="scope.row.experimentResult.key"
                  @change="changeExperimentResult(scope.row)"
                  placeholder="实验结论"
                >
                  <el-option
                    v-for="(item, key, index) in dicts.EXPERIMENT_RESULT"
                    :key="index"
                    :label="item"
                    :value="key"
                  />
                </el-select>
              </template>
            </el-table-column>
          </el-table>

          <el-row>
            <el-col :span="8">
              <el-form-item label="实验人员:" prop="experimentResultMan">
                <el-input
                  size="mini"
                  style="width:300px"
                  v-model="auditFormData.experimentResultMan"
                  placeholder="输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="审核人员:" prop="experimentCheckMan">
                <el-input
                  size="mini"
                  style="width:300px"
                  v-model="auditFormData.experimentCheckMan"
                  placeholder="输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="审核日期:" prop="experimentCheckTime">
                <el-date-picker
                  size="mini"
                  v-model="auditFormData.experimentCheckTime"
                  type="date"
                  style="width:300px"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="24">
            <div style="display:flex;widht:100%;justify-content: center;margin-top:10px">
              <el-button size="small" type="primary" @click="clickAuditSeav">保存</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

    <!-- 点击查看 -->
    <el-dialog width="65%" title="实验数据" :visible.sync="seeShow" append-to-body>
      <!-- 表格 -->
      <el-row style="line-height: 1.5;border:1px solid">
        <el-col
          :span="5"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >筛查项目</el-col>
        <el-col
          :span="3"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >检测指标</el-col>
        <el-col
          :span="3"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >检测值</el-col>
        <el-col
          :span="5"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >正常参考值</el-col>
        <el-col
          :span="8"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;"
        >筛查结果</el-col>
        <!-- hint -->
      </el-row>
      <!-- 表格内容 -->
      <el-row
        style="line-height: 1.5;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;"
      >
        <div v-for="(item, index) in seeData" :key="index">
          <el-col
            :span="5"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.indicatorCodeName }}&nbsp</el-col>
          <el-col
            :span="3"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.indicatorCode }}&nbsp</el-col>
          <el-col
            :span="3"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.experimentValue }}{{ item.units }}&nbsp</el-col>
          <el-col
            :span="5"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.referenceValue }}&nbsp</el-col>
          <el-col
            :span="8"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.hint }}&nbsp</el-col>
        </div>
      </el-row>
    </el-dialog>

    <!-- 打印 -->
    <el-dialog width="65%" title="布板打印" :visible.sync="printShow" append-to-body>
      <print :dataList="printData" v-if="printShow"></print>
      <span slot="footer" class="dialog-footer flex">
        <el-button size="small" v-print="'#print'" type="primary" style="padding: 6px 19px;">打 印</el-button>
      </span>
    </el-dialog>

    <!-- 布板 -->
    <el-dialog
      width="90%"
      append-to-body
      id="experimentData-dialog"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="布板"
      :visible.sync="bubanShow"
    >
      <el-form
        ref="basicForm"
        :rules="bubanAddFormRules"
        :inline="true"
        :model="bubanAddForm"
        class="demo-form-inline"
        size="small"
        label-width="100px"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="实验批号:" prop="batchNumber">
              <el-input size="mini" v-model="bubanAddForm.batchNumber" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板方案:" prop="swatchId.key">
              <el-select
                size="mini"
                v-model="bubanAddForm.swatchId.key"
                placeholder="选择"
                @change="swatchIdChanage"
              >
                <el-option
                  v-for="(item, index) in swatchList"
                  :key="index"
                  :label="item.swatchName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板人员:" prop="swatchMan">
              <el-input size="mini" v-model="bubanAddForm.swatchMan" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板日期:" prop="swatchTime">
              <el-date-picker
                size="mini"
                v-model="bubanAddForm.swatchTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试剂1:" prop="reagent1.key">
              <el-select size="mini" v-model="bubanAddForm.reagent1.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryReagentList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试剂2:">
              <el-select size="mini" v-model="bubanAddForm.reagent2.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryReagentList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="质控品:" prop="qualityControl.key">
              <el-select size="mini" v-model="bubanAddForm.qualityControl.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryQualityList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="选中位置:">
              <el-input size="mini" disabled v-model="banItem.selectW" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="起始编号:">
              <el-input size="mini" v-model="banItem.startCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="终止编号:">
              <el-input size="mini" v-model="banItem.endCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="选中条码:">
              <el-input size="mini" disabled v-model="banItem.selectCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板方向:">
              <el-radio-group disabled v-if="direction.key">
                <el-radio-button label="heng">{{direction.data}}</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <div style="display: flex;justify-content: center;margin:10px 0">
              <el-button type="primary" size="mini" @click="clickSet">设置</el-button>
              <el-button type="primary" size="mini" @click="clickSeave">保存</el-button>
              <el-button
                type="primary"
                size="mini"
                @click="clickQing"
                :disabled="bubanAddForm.swatchId.key? false: true"
              >清空布板</el-button>
            </div>
          </el-col>

          <!-- 表格 -->
          <el-col :span="10">
            <div id="ban-table-tow">
              <el-table
                v-loading="loading"
                :data="queryRecheckData"
                style="width: 100%;padding:5px;"
                :header-cell-style="{
                  background: '#333333',
                  color: '#ffffff',
                  textAlign: 'center'
                }"
                @row-dblclick="clickRowDB"
                id="sxtb"
              >
                <el-table-column align="center" type="index" width="35" />
                <el-table-column align="center" prop="expNum" label="实验编号" width="110" />
                <el-table-column align="center" prop="bloodProperty.data" label="属性" width="110" />
                <el-table-column align="center" prop="bloodReview.data" label="原血复查" width="100">
                  <template slot-scope="scope">
                    <span
                      :style="
                        scope.row.bloodReview.data == '是' ? 'color:red' : ''
                      "
                    >{{ scope.row.bloodReview.data }}</span>
                  </template>
                </el-table-column>
                <el-table-column align="center" prop="barCode" label="条形码号" width="110" />
                <el-table-column align="center" prop="bloodNum" label="采血编号" width="110" />
                <el-table-column align="center" />
              </el-table>
            </div>
            <div id="ban-table-tow">
              <el-table
                v-loading="importLoading"
                :data="queryNormalData"
                style="width: 100%;padding:5px;"
                :header-cell-style="{
                  background: '#333333',
                  color: '#ffffff',
                  textAlign: 'center'
                }"
                @row-dblclick="clickRowDB"
                id="sxtb"
              >
                <el-table-column align="center" type="index" width="36" />
                <el-table-column align="center" prop="expNum" label="实验编号" width="110" />
                <el-table-column align="center" prop="bloodProperty.data" label="属性" width="110" />
                <el-table-column align="center" prop="barCode" label="条形码号" width="110" />
                <el-table-column align="center" prop="bloodNum" label="采血编号" width="110" />
                <el-table-column align="center" />
              </el-table>
            </div>
          </el-col>
          <!-- 布板 -->
          <el-col :span="14">
            <buBan
              style="padding:10px 0"
              v-if="banShow"
              @getDataList="getDataList"
              @chanageDataList="chanageDataList"
              @selectRow="selectRow"
              ref="buBanRef"
              :banTotal="banTotal"
              :dataList="banData"
              :codeList="codeList"
              :rowList="rowList"
              :columnList="columnList"
              :rowNum="rowNum"
              :direction="direction"
              :colNum="colNum"
            ></buBan>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import importExcel from "@/api/upload.js";
import DeliveryManageApi from "@/api/DeliveryManage.js";
import { initDicts } from "@/utils/commons";
import print from "./print.vue";
import buBan from "@/components/ban/buBan";
import QualityManageApi from "@/api/QualityManage.js";
import ConsumableManageApi from "@/api/ConsumableManage.js";

export default {
  components: {
    print,
    buBan
  },
  data() {
    return {
      // 转菊花
      loading: false,
      // 点击查看
      seeShow: false,
      // 审核弹窗
      auditShow: false,
      // 打印显示
      printShow: false,
      // 查看数据
      seeData: [],
      // 页条数
      pageSize: 10,
      // 页数
      pageIndex: 1,
      // 表格数据
      tableData: [],
      // 选中数据
      selectList: [],
      // 查询数据
      basicData: {
        current: 1,
        map: {},
        model: {
          batchNumber: "",
          experimentCode: {
            data: "",
            key: ""
          },
          flowStatus: {
            data: "",
            key: ""
          },
          qualityControl: "",
          reagent1: "",
          reagent2: "",
          swatchId: {
            key: ""
          },
          swatchMan: "",
          swatchTimeStartEnd: {
            end: "",
            start: ""
          }
        },
        order: "descending",
        size: 10,
        sort: "id"
      },
      // 总数
      total: 0,
      // 字典
      dicts: {
        EXPERIMENT_CODE: {}, //实验项目
        EXPERIMENT_RESULT: {} //实验结论
      },
      // 审核弹窗数据
      auditList: [],
      user: this.$store.state.account.user.name,
      // 审核提交数据
      auditFormData: {
        experimentCode: {
          data: "",
          key: ""
        },
        experimentSwatchId: "",
        list: [],
        experimentResultMan: this.$store.state.account.user.name,
        experimentCheckMan: this.$store.state.account.user.name,
        experimentReportMan: "",
        experimentResultTime: "",
        experimentCheckTime: "",
        experimentReportTime: ""
      },
      // 打印数据
      printData: {
        dto: {
          batchNumber: "",
          swatchId: {
            key: ""
          },
          swatchMan: "",
          swatchTime: "",
          qualityControl: "",
          experimentCode: "",
          sampleCount: ""
        }
      },
      // 审核查询数据
      queryData: {
        expNum: "",
        momName: "",
        experimentValueResult: {
          key: "",
          data: ""
        }
      },
      // 布板数据··············
      // 复检样本
      queryRecheckData: [],
      // 正常样本
      queryNormalData: [],
      // 复检样本转菊花
      queryRechecLoading: false,
      // 正常样本
      queryNormal: [],
      // 正常样本转菊花
      queryNormalLoading: false,
      // 布板弹窗
      bubanShow: false,
      // 正常样本表格转菊花
      importLoading: false,
      // 打印显示
      printShow: false,
      // 布板保存数据
      bubanAddForm: {
        direction: {
          data: "",
          key: ""
        },
        batchNumber: "",
        experimentCode: {
          key: ""
        },
        qualityControl: {
          key: ""
        },
        reagent1: {
          key: ""
        },
        reagent2: {
          key: ""
        },
        swatchId: {
          key: ""
        },
        swatchMan: this.$store.state.account.user.name,
        swatchTime:
          new Date().getFullYear().toString() +
          "-" +
          ((new Date().getMonth() + 1).toString() < 10
            ? "0" + (new Date().getMonth() + 1).toString()
            : (new Date().getMonth() + 1).toString()) +
          "-" +
          (new Date().getDate().toString() < 10
            ? "0" + new Date().getDate().toString()
            : new Date().getDate().toString()),
        swatchValue: []
      },
      // 板验证
      bubanAddFormRules: {
        batchNumber: [{ required: true, message: "   ", trigger: "change" }],
        "swatchId.key": [{ required: true, message: "   ", trigger: "change" }],
        swatchMan: [{ required: true, message: "   ", trigger: "change" }],
        swatchTime: [{ required: true, message: "   ", trigger: "change" }],
        "reagent1.key": [{ required: true, message: "   ", trigger: "change" }],
        "qualityControl.key": [
          { required: true, message: "   ", trigger: "change" }
        ]
      },
      // 板本地操作数据
      banItem: {
        selectW: "",
        barcode: "",
        startCode: "",
        endCode: "",
        selectCode: ""
      },
      // 布板方案
      swatchList: [],
      // 试剂
      queryReagentList: [],
      // 质控品
      queryQualityList: [],
      // 布板数据
      banData: [],
      // 板数量
      banTotal: 0,
      // 显示布板
      banShow: false,
      // 当前点击行
      clickRow: [],
      // 选中的编码
      codeList: [],
      // 布板列数
      rowList: [],
      // 布板行数
      columnList: [],
      // 表格方向
      direction: {
        data: "",
        key: "" // vertical
      },
      rowNum: 0,
      colNum: 0,
      hintList: [] //审核统计
    };
  },
  computed: {
    // 模糊搜索
    tables() {
      if (this.auditList.length > 0) {
        let dataList = JSON.parse(JSON.stringify(this.auditList));
        let queryList = [];
        if (this.queryData.expNum != "") {
          let i = 0;
          dataList.filter(data => {
            Object.keys(data).some(key => {
              if (key == "expNum") {
                if (
                  String(data[key])
                    .toLowerCase()
                    .indexOf(this.queryData.expNum) > -1
                ) {
                  queryList.push(data);
                  i++;
                }
              }
            });
          });
          if (i == 0) {
            this.$message.error("没有当前实验编号");
          }
        } else if (this.queryData.momName != "") {
          dataList.filter(data => {
            Object.keys(data).some(key => {
              if (key == "momName") {
                if (
                  String(data[key])
                    .toLowerCase()
                    .indexOf(this.queryData.momName) > -1
                ) {
                  queryList.push(data);
                }
              }
            });
          });
        } else if (this.queryData.experimentValueResult.key != "") {
          dataList.filter(data => {
            Object.keys(data).some(key => {
              if (key == "experimentValueResult") {
                if (
                  String(data[key].key)
                    .toLowerCase()
                    .indexOf(this.queryData.experimentValueResult.key) > -1
                ) {
                  queryList.push(data);
                }
              }
            });
          });
        } else {
          queryList = JSON.parse(JSON.stringify(this.auditList));
        }
        //设置标题，alpha，beta，M-Hb
        queryList.forEach((item, index) => {
          if (item.experimentCode.key == "THA") {
            if (item.experimentValue) {
              for (let key in item.experimentValue) {
                queryList[index][key] =
                  item.experimentValue[key].experimentValue +
                  item.experimentValue[key].units;
              }
            }
          }
        });

        return queryList;
      }
    }
  },
  mounted() {
    initDicts(["EXPERIMENT_CODE", "EXPERIMENT_RESULT"], this.dicts);
    this.getList(this.basicData);
  },
  methods: {
    // 布板#################################
    // 清空布板
    clickQing() {
      this.$confirm("是否清空布板?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.banData.forEach(item => {
          if (item.m == "") {
            item.s = "";
          }
        });
      });
    },
    // 保存
    clickSeave() {
      this.$refs["basicForm"].validate(valid => {
        if (valid) {
          DeliveryManageApi.addSample.putData(this.bubanAddForm).then(res => {
            if (res.status === 200) {
              this.$message({
                type: "success",
                message: res.statusText
              });
              this.bubanShow = false;
              this.resultData();
              this.getList(this.basicData);
            } else {
              this.$message.error(res.statusText);
            }
          });
        } else {
          return false;
        }
      });
    },
    // 点击布板
    clickBuban() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择数据");
        return;
      } else if (this.selectList.length > 1) {
        this.$message.error("只能选择一条数据");
        return;
      }
      let data = this.selectList[0];
      this.resultData();
      this.direction = Object.assign({}, data.direction);
      this.bubanShow = true;
      this.bubanAddForm.batchNumber = data.batchNumber;
      this.bubanAddForm.swatchId = data.swatchId;
      this.bubanAddForm.experimentCode = data.experimentCode;
      this.bubanAddForm.swatchMan = data.swatchMan;
      this.bubanAddForm.reagent1 = data.reagent1;
      this.bubanAddForm.reagent2 = data.reagent2;
      this.bubanAddForm.qualityControl = data.qualityControl;
      this.bubanAddForm.direction = data.direction;

      // 查询已存复检
      DeliveryManageApi.experimentData
        .querySavedRecheck({
          experimentSwatchId: data.id
        })
        .then(res => {
          this.queryRecheckData = res.data.data;
        });
      // 查询已存初验
      DeliveryManageApi.experimentData
        .querySavedNormal({
          experimentSwatchId: data.id
        })
        .then(res => {
          this.queryNormalData = res.data.data;
        });
      // 查询已存布板
      DeliveryManageApi.experimentData
        .querySavedSwatch({
          experimentSwatchId: data.id
        })
        .then(res => {
          this.bubanAddForm = res.data.data;
          this.banData = res.data.data.swatchValue;
          this.banTotal = 0;
          res.data.data.swatchValue.forEach(item => {
            if (item.ban > this.banTotal) {
              this.banTotal++;
            }
          });
          this.columnList = [];
          this.rowList = [];
          this.filColumnList(res.data.data.swatchValue).forEach(
            (item, index) => {
              this.columnList[index] = {
                id:
                  this.direction.key == "horizontal"
                    ? item
                    : this.$rowData[index],
                type: ""
              };
            }
          );
          if (this.columnList[0].type != "banIndex") {
            this.columnList.unshift({ id: "1", type: "banIndex" });
          }
          this.rowList = this.filRowList(res.data.data.swatchValue); //根据布板数组过滤行数
          this.banShow = true;
          // 重置布板数据
          setTimeout(() => {
            this.$refs.buBanRef.getList();
          }, 200);

          // 方案名称
          let swatchSchemeManage = {
            current: 1,
            map: {},
            model: {
              experimentCode: {
                data: "",
                key: this.bubanAddForm.experimentCode.key
              },
              swatchName: ""
            },
            order: "descending",
            size: 10,
            sort: "id"
          };
          QualityManageApi.swatchSchemeManage
            .page(swatchSchemeManage)
            .then(res => {
              this.swatchList = res.data.data.records;
              this.swatchList.forEach(item => {
                if (item.id == this.bubanAddForm.swatchId.key) {
                  this.rowNum = item.rowNum;
                  this.colNum = item.colNum;
                }
              });
            });

          // 试剂名称
          ConsumableManageApi.reagentManage
            .queryReagent({ code: this.bubanAddForm.experimentCode.key })
            .then(res => {
              this.queryReagentList = res.data.data;
            });
          // 质控品
          ConsumableManageApi.reagentManage
            .queryQuality({ code: this.bubanAddForm.experimentCode.key })
            .then(res => {
              this.queryQualityList = res.data.data;
            });
        });
    },
    // 重置数据
    resultData() {
      this.banShow = false;
      this.bubanAddForm = {
        direction: {
          data: "",
          key: ""
        },
        batchNumber: "",
        experimentCode: {
          key: ""
        },
        qualityControl: {
          key: ""
        },
        reagent1: {
          key: ""
        },
        reagent2: {
          key: ""
        },
        swatchId: {
          key: ""
        },
        swatchMan: this.$store.state.account.user.name,
        swatchTime:
          new Date().getFullYear().toString() +
          "-" +
          ((new Date().getMonth() + 1).toString() < 10
            ? "0" + (new Date().getMonth() + 1).toString()
            : (new Date().getMonth() + 1).toString()) +
          "-" +
          (new Date().getDate().toString() < 10
            ? "0" + new Date().getDate().toString()
            : new Date().getDate().toString()),
        swatchValue: []
      };
      this.banItem = {
        selectW: "",
        barcode: "",
        startCode: "",
        endCode: "",
        selectCode: ""
      };
    },
    // 点击设置
    clickSet() {
      if (this.bubanAddForm.swatchId.key == "") {
        this.$message.error("请选择布板方案");
      } else if (this.banItem.selectW == "") {
        this.$message.error("请选择起始位置");
      } else if (
        (this.banItem.startCode != "" && this.banItem.endCode == "") ||
        (this.banItem.startCode == "" && this.banItem.endCode != "")
      ) {
        this.$message.error("编号无数字部分");
      } else if (this.banItem.startCode > this.banItem.endCode) {
        this.$message.error("起始编号不能大于终止编号");
      } else if (this.banItem.endCode - this.banItem.startCode > 2000) {
        this.$message.error("编号区间跨度过大");
      } else if (this.banItem.startCode != "" && this.banItem.endCode != "") {
        // this.codeList = [];
        // let codeList = [];
        if (
          isNaN(Number(this.banItem.startCode)) ||
          isNaN(Number(this.banItem.endCode))
        ) {
          this.$message.error("填充的实验编号不能存在英文或者特殊符号");
          return;
        }
        // for (
        //   let index = this.banItem.startCode;
        //   index < Number(this.banItem.endCode) + 1;
        //   index++
        // ) {
        //   codeList.push(index);
        // }
        // this.codeList = codeList;
        // if (this.codeList.length > 0) {
        //   setTimeout(() => {
        //     this.$refs.buBanRef.setCode();
        //   }, 300);
        // }
        let unList = []; //缺少的样本
        this.codeList = [];
        let codeList = [];
        let tableList = [...this.queryRecheckData, ...this.queryNormalData];

        tableList.forEach((item, index) => {
          if (
            item.expNum >= this.banItem.startCode &&
            item.expNum <= this.banItem.endCode
          ) {
            codeList.push(item.expNum);
          }
        });
        for (
          let index = this.banItem.startCode;
          index < Number(this.banItem.endCode) + 1;
          index++
        ) {
          if (codeList.indexOf(index.toString()) < 0) {
            unList.push(index);
          }
        }
        this.codeList = codeList;
        if (unList.length > 0) {
          this.$confirm(
            `缺少以下可布板样本(${
              unList.length
            })：<div style="width: 280px;overflow: hidden;white-space: normal;word-break: break-all;max-height:360px;overflow: auto;">${unList.toString()}</div>，是否对可布板样本进行布板？`,
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              dangerouslyUseHTMLString: true,
              type: "warning"
            }
          ).then(() => {
            if (this.codeList.length > 0) {
              setTimeout(() => {
                this.$refs.buBanRef.setCode();
              }, 300);
            }
          });
        } else {
          if (this.codeList.length > 0) {
            setTimeout(() => {
              this.$refs.buBanRef.setCode();
            }, 300);
          }
        }
      } else {
        let list = this.banData;
        let arr = list.map(item => item.s);
        this.codeList = [];
        this.queryNormalData.forEach((item, index) => {
          if (arr.indexOf(item.expNum) > -1) {
          } else {
            this.codeList.push(item.expNum);
          }
        });
        if (this.codeList.length > 0) {
          setTimeout(() => {
            this.$refs.buBanRef.setCode();
          }, 300);
        }
      }
    },
    // 点击当前行设置布板内部数据
    clickRowDB(v) {
      let list = this.banData;
      let arr = list.map(item => item.s);
      this.codeList = [];
      if (arr.indexOf(v.expNum) > -1) {
        this.$message.error("此条形码号样本已经布板");
      } else {
        this.codeList.push(v.expNum);
      }
      if (this.codeList.length > 0) {
        setTimeout(() => {
          this.$refs.buBanRef.setCode();
        }, 300);
      }
    },
    // 设置共享布板
    getDataList() {
      this.banShow = false;
      this.banData = JSON.parse(localStorage.getItem("banList"));
      setTimeout(() => {
        this.banShow = true;
      }, 50);
    },
    // 获取当前点击行
    selectRow(v) {
      this.clickRow = v;
      this.banItem.selectW = v.pos;
    },
    // 布板内数据变化
    chanageDataList(v) {
      var dataList = this.queryRecheckData.concat(this.queryNormalData);
      var codeList = [];
      dataList.forEach(item => {
        codeList.push(item.expNum.toString());
      });
      v.forEach((item, index) => {
        codeList.forEach(i => {
          if (item.s == i) {
            item.exist = "Y";
          }
        });
      });
      this.bubanAddForm.swatchValue = v;
    },
    // 选择布板方案
    swatchIdChanage(v) {
      QualityManageApi.swatchSchemeManage
        .getById(this.bubanAddForm.swatchId.key)
        .then(res => {
          this.banData = res.data.data.swatchModel;
          this.banTotal = res.data.data.swatchNum;
          this.direction = Object.assign({}, res.data.data.direction);
          this.columnList = [];
          this.rowList = [];
          this.filColumnList(res.data.data.swatchModel).forEach(
            (item, index) => {
              this.columnList[index] = {
                id:
                  this.direction.key == "horizontal"
                    ? item
                    : this.$rowData[index],
                type: ""
              };
            }
          );
          if (this.columnList[0].type != "banIndex") {
            this.columnList.unshift({ id: "1", type: "banIndex" });
          }
          this.rowList = this.filRowList(res.data.data.swatchModel); //根据布板数组过滤行数
          this.banShow = true;
          // 重置布板数据
          setTimeout(() => {
            this.$refs.buBanRef.getList();
          }, 200);
        });
    },
    // 布板结束##################################
    // 修改实验结论
    changeExperimentResult(row) {
      this.auditList.forEach((item, index) => {
        if (item.sampleId == row.sampleId) {
          this.$set(this.auditList, index, row);
        }
      });
    },
    // 重置搜索
    clickResult() {
      this.queryData = {
        expNum: "",
        momName: "",
        experimentValueResult: {
          key: "",
          data: ""
        }
      };
    },
    // 设置单元格样式
    tableRowStyle({ row, rowIndex }) {
      if (row.experimentValueResult.key != "normal") {
        return { "background-color": "#baccef", color: "#606266" };
      }
    },
    // 过滤去重(获取布板数)
    filBanList(arr) {
      let data = [];
      arr.forEach(item => {
        data.push(item.ban);
      });
      return Array.from(new Set(data));
    },
    // 过滤去重(获取布板列数)
    filRowList(arr) {
      let data = [];
      arr.forEach(item => {
        data.push(item.col);
      });
      return Array.from(new Set(data));
    },
    // 过滤去重(获取布板列数)
    filColumnList(arr) {
      let data = [];
      arr.forEach(item => {
        data.push(
          this.direction.key == "horizontal" ? item.r : item.pos.split("-")[1]
        );
      });
      return Array.from(new Set(data));
    },
    // 点击打印
    clickPrint() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要打印的数据！");
        return;
      }
      if (this.selectList.length > 1) {
        this.$message.error("只能选择一条数据打印！");
        return;
      }
      let rowList = [];
      let columnList = [];
      let data = {};
      this.filColumnList(this.selectList[0].swatchValue).forEach(
        (item, index) => {
          columnList[index] = {
            id:
              this.selectList[0].direction.key == "horizontal"
                ? item
                : this.$rowData[index],
            type: ""
          };
        }
      );
      if (columnList[0].type != "banIndex") {
        columnList.unshift({ id: "1", type: "banIndex" });
      }
      rowList = this.filRowList(this.selectList[0].swatchValue); //根据布板数组过滤行数

      data = {
        dto: this.selectList[0],
        columnList: columnList,
        rowList: rowList,
        direction: this.selectList[0].direction,
        banTotal: this.filBanList(this.selectList[0].swatchValue).length,
        tableList: this.selectList[0].swatchValue
      };
      this.printData = data;
      this.printShow = true;
    },
    // 点击查看
    clickSeeExpValue(v) {
      this.seeShow = true;
      let sortData = [];
      for (let key in v) {
        sortData.push(v[key]);
      }
      this.seeData = this.$keysrt(sortData, "sortValue");
    },
    // 选择数据
    clickDelete() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要删除的数据");
        return;
      }
      // 加删除验证
      this.$confirm(`是否删除${this.selectList.length}条数据?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.selectList.forEach(item => {
          DeliveryManageApi.dataAudit
            .delete({
              "ids[]": item.id
            })
            .then(res => {
              this.getList(this.basicData);
            });
        });
      });
    },
    // 审核保存
    clickAuditSeav() {
      this.auditList.forEach(item => {
        item.experimentCheckStatus = "Y";
        item.experimentResultTime = this.auditFormData.experimentCheckTime;
        item.experimentCheckTime = this.auditFormData.experimentCheckTime;
        item.experimentReportTime = this.auditFormData.experimentReportTime;
        item.experimentCheckMan = this.auditFormData.experimentCheckMan;
        item.experimentReportMan = this.auditFormData.experimentReportMan;
        item.experimentResultMan = this.auditFormData.experimentResultMan;
      });
      this.auditFormData.list = this.auditList;
      DeliveryManageApi.dataAudit.auditSave(this.auditFormData).then(res => {
        if (res.status == 200) {
          this.$message({
            type: "success",
            message: res.statusText
          });
          this.getList(this.basicData);
          this.auditShow = false;
        } else {
          this.$message.error(res.statusText);
        }
      });
    },
    // 点击审核
    clickAudit() {
      if (this.selectList.length > 1) {
        this.$message.error("只能选择一条数据！");
        return;
      }
      if (this.selectList.length == 0) {
        this.$message.error("请选择一条数据！");
        return;
      }
      this.auditShow = true;
      this.auditFormData.experimentCode = this.selectList[0].experimentCode;
      this.auditFormData.experimentSwatchId = this.selectList[0].id;
      let date =
        new Date().getFullYear().toString() +
        "-" +
        ((new Date().getMonth() + 1).toString() < 10
          ? "0" + (new Date().getMonth() + 1).toString()
          : (new Date().getMonth() + 1).toString()) +
        "-" +
        (new Date().getDate().toString() < 10
          ? "0" + new Date().getDate().toString()
          : new Date().getDate().toString());
      this.auditFormData.experimentResultTime = date;
      this.auditFormData.experimentCheckTime = date;

      DeliveryManageApi.dataAudit
        .auditView({
          experimentSwatchId: this.selectList[0].id
        })
        .then(res => {
          res.data.data.forEach(item => {
            if (item.experimentResult.key == null) {
              item.experimentResult.key = "normal";
            }
          });
          this.auditList = res.data.data;
        });
      DeliveryManageApi.dataAudit
        .auditInfo({
          experimentSwatchId: this.selectList[0].id
        })
        .then(res => {
          console.log(res.data.data);

          this.hintList = res.data.data.hintList;
          let date =
            new Date().getFullYear().toString() +
            "-" +
            ((new Date().getMonth() + 1).toString() < 10
              ? "0" + (new Date().getMonth() + 1).toString()
              : (new Date().getMonth() + 1).toString()) +
            "-" +
            (new Date().getDate().toString() < 10
              ? "0" + new Date().getDate().toString()
              : new Date().getDate().toString());

          this.auditFormData.experimentResultMan = res.data.data.result
            .experimentResultMan
            ? res.data.data.result.experimentResultMan
            : this.$store.state.account.user.name;
          this.auditFormData.experimentCheckMan = res.data.data.result
            .experimentCheckMan
            ? res.data.data.result.experimentCheckMan
            : this.$store.state.account.user.name;
          this.auditFormData.experimentCheckTime = res.data.data.result
            .experimentCheckTime
            ? res.data.data.result.experimentCheckTime
            : date;
        });
    },
    // 获取数据
    getList(data) {
      this.loading = true;
      DeliveryManageApi.dataAudit
        .page(data)
        .then(res => {
          if (res.status === 200) {
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
          } else {
            this.$message.error(res.statusText);
          }
        })
        .finally(() => (this.loading = false));
    },
    //点击全选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 点击分页
    handleSizeChange: function(val) {
      this.basicData.size = val;
      this.getList(this.basicData);
    },
    // 选择页码
    handleCurrentChange: function(currentPage) {
      this.basicData.current = currentPage;
      this.getList(this.basicData);
    },
    // 选中数据操作
    selectChanage(v) {
      this.selectList = v;
    }
  }
};
</script>

<style lang="less" >
#dataaudit {
}
#experimentData-dialog {
  #sxtb {
    td {
      padding: 5px 0 !important;
    }
    th {
      padding: 5px 0 !important;
    }
  }
  display: flex;
  justify-content: center;
  align-items: center;
  .el-dialog {
    margin-top: 0 !important;
  }
  .el-message-box__message {
    width: 280px;
    overflow: hidden;
    white-space: normal;
    word-break: break-all;
  }
  #ban-table-tow {
    .el-table__body-wrapper {
      height: 200px !important;
      overflow-y: auto;
    }
  }
  .el-dialog__title {
    color: #fff;
  }
  .el-form-item__content {
    width: 80%;
    .el-select {
      width: 100%;
    }
    .el-date-editor {
      width: 100%;
    }
  }
}
</style>
